package com.liang.publics.util;

import android.content.Context;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class MyStringUtil {

    public  static  String getmanufacturer(String manufacturer){
        String mymanufacturer  = "";
        if(manufacturer!=null) {
            //VIVO
            if ((manufacturer.indexOf("VIVO") > -1 || manufacturer.indexOf("vivo") > -1)) {
                mymanufacturer = "vivo";
            } else if ((manufacturer.indexOf("OPPO") > -1 || manufacturer.indexOf("oppo") > -1)) {
                mymanufacturer = "oppo";
            } else if ((manufacturer.indexOf("HUAWEI") > -1 || manufacturer.indexOf("huawei") > -1)
                    || (manufacturer.indexOf("HONOR") > -1 || manufacturer.indexOf("honor") > -1)
            ) {
                mymanufacturer = "huawei";
            }else if ((manufacturer.indexOf("xiaomi") > -1 || manufacturer.indexOf("XIAOMI") > -1)
                    || (manufacturer.indexOf("redmi") > -1 || manufacturer.indexOf("REDMI") > -1)
            ) {
                mymanufacturer = "xiaomi";
            }
        }

        return  mymanufacturer;
    }






    //上报服务器risk接口
    public static String getRiskInfo(Context context){
        List<String> list = new ArrayList();
        if(!DeviceUtils.hasSimCard(context)){
            list.add("nosim");
        }
        if(EmulatorUtils.isEmulator(context)){
            list.add("emulator");
        }
        if(RootUtil.isCurrDeviceRooted()){
            list.add("root");
        }
        if(DeviceUtils.isWifiProxy(context)){
            list.add("proxy");
        }
        if(DeviceUtils.isVpnUsed() ){
            list.add("vpn");
        }
        if(DeviceUtils.usbStatus(context)){
            list.add("debug");
        }

//        final PackageManager packageManager = context.getPackageManager();//获取packagemanager
//        List<PackageInfo> pInfo = packageManager.getInstalledPackages(0);//获取所有已安装程序的包信息
//        if (pInfo != null) {
//            for (int i = 0; i < pInfo.size(); i++) {
//                String packageName = pInfo.get(i).packageName.toLowerCase();
//                for (int j=0;j<aryBlackPackage.length;j++ ) {
//                    if (packageName.contains(aryBlackPackage[j].toLowerCase())) {
//                        if(j==0) {
//                            addAppToList(list, "xuexi");
//                        }else if(j == 1){
//                            addAppToList(list, "ribao");
//                        }else if(j== 2){
//                            addAppToList(list, "tustme");
//                        }else if(j== 3){
//                            addAppToList(list, "anjian");
//                        }else{
//                            addAppToList(list, aryBlackPackage[j]);
//                        }
//                    }
//                }
//            }
//        }
        String str ="";
        for(int k=0;k<list.size();k++){
            String val = list.get(k);
            str += val;
            if(k<list.size()-1){
                str+="|";
            }
        }
        return  str;
    }


    public static boolean  dayIfAdOne(String type){//是否为首次加载广告
        boolean bo = false;
//        String key =  getCurrentDateFormatted()+"_"+type;//每日一次控制
//        bo = SharedPreferencesUtil.getStatus(key);
        return  bo;
    }
    public static  void   setDayIfAdOne(String type){//标记当前已经加载
        String key = getCurrentDateFormatted()+"_"+type;//每日一次控制
        SharedPreferencesUtil.saveStatus(key, true);

     }


    public static String getCurrentDateFormatted() {
        // 创建一个 Calendar 实例来获取当前日期
        java.util.Calendar calendar = java.util.Calendar.getInstance();

        // 创建一个 SimpleDateFormat 对象，并设置所需的日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");

        // 使用 Calendar 实例格式化日期
        String formattedDate = dateFormat.format(calendar.getTime());

        // 返回格式化后的日期字符串
        return formattedDate;
    }
}
